#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<stdlib.h>

int main(int argc,char* argv[])
{
	if(argc != 2)
	{
		printf("Usage:%s",argv[0]);
		return 1;
	}
	umask(0);
	int fd = open(argv[1],O_CREAT | O_WRONLY | O_TRUNC ,0666);
	if(fd<0)
	{
		perror("open");
		return 1;
	}
	dup2(fd,1);
	const char* meg = "hello bit";
	int cnt = 5;
	while(cnt--)
	{
		char buffer[16];
		snprintf(buffer,sizeof(buffer),"%s\n",meg);
		write(1,buffer,strlen(buffer));
	}
	close(fd);
	return 0;
}
